# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

from .db import connection


class BaiduPipeline(object):
    def process_item(self, item, spider):
        with connection:
            result = connection.execute(
                "insert into user_info (`name`, `age`, `gender`) values('{}', {}, '{}')".format(item["name"],
                                                                                              item['age'],
                                                                                             item['gender']))
            print("ERROR" if result < 1 else "SUCCESS")
        return item